# -*- coding:utf-8 -*-
"""
Author：Administrator
Date:2021年11月28日
"""
import pandas as pd

df = pd.DataFrame()
url_list=["http://www.espn.com/nba/salaries/_/seansontype/4"]
for i in range(2,13):
	url = 'http://www.espn.com/nba/salaries/_/page/%s/seansontype/4' % i
	url_list.append(url)

# 遍历网页中的table标签读取网页表格数据
for url in url_list:
	df = df.append(pd.read_html(url),ignore_index=True)

# 列表解析:遍历dataframe对象的第3列,以子字符串$开头
df = df[[x.startswith('$') for x in df[3]]]
print(df)
df.to_csv('NBA.csv',header=['RK','NAME',"TEAM","SALARY"],index=False) # 导出.csv文件
